//
//  CardDetailCell.m
//  jiyujiaProgram
//
//  Created by Jame on 15/12/16.
//  Copyright © 2015年 中良 赵. All rights reserved.
//

#import "CardDetailCell.h"
#import "CardModel.h"

@implementation CardDetailCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setCellWithModel:(NSArray *)model WithIndexPath:(NSIndexPath *)index isHidden:(BOOL)isHidden
{
    CardData *data = model[index.section];
    self.titleLabel.text = data.title;
    self.contentLabel.text = data.content;
    self.commentLabel.hidden = isHidden;
    self.commentLabel.text = [NSString stringWithFormat:@"%@赞    %@回复",data.praiseCount,data.commentsCount];
    self.nameLabel.text = data.name;
    NSString *image = [data.imgUrls stringByReplacingOccurrencesOfString:@"," withString:@""];
    [self.titleImage sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:ECIMAGENAME(@"placeImage.png")];
    
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[data.create_time doubleValue]/1000];
    NSString *dateString = [self compareCurrentTime:date];
    self.timeLabel.text = [NSString stringWithFormat:@"%@",dateString];
}



- (NSString *)compareCurrentTime:(NSDate*)compareDate
{
    NSTimeInterval  timeInterval = [compareDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    if (timeInterval < 60) {
        result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:@"%d分前",temp];
    }
    
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:@"%d小前",temp];
    }
    
    else if((temp = temp/24) <30){
        result = [NSString stringWithFormat:@"%d天前",temp];
    }
    
    else if((temp = temp/30) <12){
        result = [NSString stringWithFormat:@"%d月前",temp];
    }
    else{
        temp = temp/12;
        result = [NSString stringWithFormat:@"%d年前",temp];
    }
    
    return  result;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
